package net.expectx.gw.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登录信息拦截器
 * @author jianhun
 * @date 2017/5/17
 */
public class ExpectXInterceptor extends HandlerInterceptorAdapter {

    private static final Logger LOGGER = LoggerFactory.getLogger(ExpectXInterceptor.class);



    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        LOGGER.info("--------------进入ExpectXInterceptor执行preHandle");
        String xRequestWith = "X-Requested-With";
        String xMLHttpRequest = "XMLHttpRequest";
        // 过滤ajax
        if (null != request.getHeader(xRequestWith)
                && xMLHttpRequest.equalsIgnoreCase(request.getHeader(xRequestWith))) {
            return true;
        }
        return true;

    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {

        super.postHandle(request, response, handler, modelAndView);

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
                                Exception ex) throws Exception {

        super.afterCompletion(request, response, handler, ex);

    }

    @Override
    public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response,
                                               Object handler) throws Exception {

        super.afterConcurrentHandlingStarted(request, response, handler);

    }

}
